let path=require('path');
let fs=require('fs');

const pathConfig=require('./config.json');

const entries=function getEntry(childDirectory,pattern,files){
    let buildPath=path.resolve(__dirname, pathConfig.build);
    let jsPath=path.resolve(buildPath,childDirectory);
    let directorys=fs.readdirSync(jsPath);
    
    for(var item of directorys){
        let file=path.join(jsPath,item);
        let stats=fs.statSync(file);

        var currentDir=childDirectory;

        currentDir=""!==currentDir?currentDir+"/":currentDir;

        if(stats.isDirectory()&&!pathConfig.ignoreDir.includes(currentDir+=item)){
            getEntry(currentDir,pattern,files);
        }
        else{
            let jsMatch=item.match(pattern);
            if(jsMatch){
                let _module=currentDir+jsMatch[1];
                files[_module]=path.resolve(buildPath,childDirectory,item);
            }
          
        }
    }
}

module.exports=entries;